<?php
namespace Home\Controller;
use Think\Controller;
class  AdsController extends Controller{
    
    /**********所有广告图片*********/
    public function getCover(){
        $cat_id=isset($_POST['cat_id'])?trim($_POST['cat_id']):null;
        $type=isset($_POST['type'])?trim($_POST['type']):null;
        if(empty($cat_id)||empty($type)){
            $requset=array('returnCode'=>999,'returnMsg'=>'所请求数据为空','returnData'=>null);
            echo json_encode($requset); exit;
        }else{
               $data=M('adsmanage')->field('cover,link,diantiAds,wenkuAds')->where(['cat_id'=>$cat_id])->find();
               if(empty($data)){
                               $requset=array('returnCode'=>999,'returnMsg'=>'空数据','returnData'=>null);
                               echo json_encode($requset); exit; break;
                   }else{
                       switch($type){
                               case 1:                                              //封面 cover 和链接地址 link
                                       $result['cover']=C('domain').$data['cover'];
                                       $result['link']=$data['link'];
                                       $requset=array('returnCode'=>0,'returnMsg'=>'返回成功','returnData'=>$result);
                                       echo json_encode($requset); exit; break;
                               case 2:                                              //点题广告图片
                                       $result['diantiAds']=C('domain').$data['diantiAds'];
                                       $requset=array('returnCode'=>0,'returnMsg'=>'返回成功','returnData'=>$result);
                                       echo json_encode($requset); exit; break;
                               case 3:                                              //资料文库广告图片
                                       $result['wenkuAds']=C('domain').$data['wenkuAds'];
                                       $requset=array('returnCode'=>0,'returnMsg'=>'返回成功','returnData'=>$result);
                                       echo json_encode($requset); exit; break;
                               default:
                                       $requset=array('returnCode'=>999,'returnMsg'=>'所请求数据有错','returnData'=>null);
                                       echo json_encode($requset); exit;
                                   }
                        }
        }
    }
}